package com.greensecurity.sim.controller;

import cn.hutool.http.HttpResponse;


import com.alibaba.fastjson.JSON;
import com.greensecurity.sim.entity.Menu;
import com.greensecurity.sim.repository.MenuRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("")
@Api(description = "菜单查询")
public class MenuController {

    @Resource
    private MenuRepository menuRepository;

    @ResponseBody
    @GetMapping("/getMenu")
    @ApiOperation(value = "查询所有菜单")
    public List<Menu> getMenu(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
      List<Menu> menus = menuRepository.findAll();
//      String menusJson = JSON.toJSONString(menus);
//      System.out.println(menusJson);
//      Cookie menu=new Cookie("menus",menusJson);
//      menu.setMaxAge(1*24*3600);
//      response.addCookie(menu);
      return menus;
    };
}
